<template>
	<view class="popup-content">
		<scroll-view scroll-y="true" class="scroll-height">
			<uni-table border stripe type="selection" :emptyText="$t('common.noData')" @selection-change="selectionChange">
				<uni-tr>
					<uni-th align="center">{{$t('equipment.meaPoint.mpName')}}</uni-th>
					<uni-th align="center" width="80">{{$t('equipment.techPara.paraType')}}</uni-th>
					<uni-th align="center" width="80">{{$t('equipment.meaPoint.unit')}}</uni-th>
				</uni-tr>
				<uni-tr v-for="(item, index) in tableData" :key="index">
					<uni-td align="center">{{item.mpName}}</uni-td>
					<uni-td align="center">{{item.mpType | codeFormat(typeList, 'name', 'key')}}</uni-td>
					<uni-td align="center">{{item.unit | codeFormat(unitList, 'name', 'key')}}</uni-td>
				</uni-tr>
			</uni-table>
		</scroll-view>
		
		<view class="botton-btn-st">
			<button @click="cancel">{{$t('baseCommon.buttons.cancel')}}</button>
			<button type="primary" @click="sure">{{$t('baseCommon.buttons.confirm')}}</button>
		</view>
	</view>
</template>

<script>
	import * as sqliteUtil from '@/utils/sqlite.js'
	import { utilities } from '@/utils/common.js'
	
	export default {
		props: {
			insp: {
				type: Object
			},
			unitList: {
				type: Array
			}
		},
		data() {
			return {
				tableData: [],
				typeList: [],
				selectedIndexs: [],
				selectedData: []
			}
		},
		mounted() {
			this.init()
		},
		methods: {
			init() {
				// 获取测点参数类型数据字典
				sqliteUtil.selectTableInfo('m_cpis_cat_dic', 'type_key', 'sbjscslx').then(res=>{
					this.typeList = res
				})
				
				sqliteUtil.selectTableInfo('m_ri_line_insp_mp', 'line_insp_id', this.insp.lineInspId).then(res=>{
					utilities.formatHumpLineTransfer(res)
					res.forEach(item => {
						if(this.insp.mpList.findIndex(r => r.mpId == item.mpId) === -1) {
							item.lineId = this.insp.lineId
							item.taskId = this.insp.taskId
							item.taskInspId = this.insp.taskInspId
							item.locaId = this.insp.locaId
							item.locaNo = this.insp.locaNo
							item.locaName = this.insp.locaName
							item.execValue = null
							item.execResult = null
							this.tableData.push(item)
						}
					})
				})
			},
			selectionChange(e) {
				this.selectedIndexs = e.detail.index
			},
			cancel() {
				this.$emit("closePop", "mp")
			},
			sure() {
				this.selectedIndexs.forEach(index => {
					this.selectedData.push(this.tableData[index])
				})
				this.$emit("confirm", this.selectedData)
			}
		}
	}
</script>

<style lang="scss" scoped>
	.popup-content {
		background-color: #f1f1f1;
		padding: 12px;
		height: calc(100vh - 92px);
	}
	
	.scroll-height {
		height: calc(100vh - 160px);
	}
	
	.botton-btn-st {
		position: fixed;
		bottom: 10px;
		width: 96%;
		left: 2%;
		display: flex;
	
		button {
			flex: 1;
			margin: 0 4px;
			font-size: 16px;
		}
	}
</style>